package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.domain.Enclosure;
import com.ruoyi.personnel.service.IEnclosureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 护士职业资格管理Controller
 *
 * @author ruoyi
 * @date 2021-03-01
 */
@Api("护士职业资格管理")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/nursing/enclosure" )
public class EnclosureController extends BaseController {

    private final IEnclosureService iEnclosureService;

    /**
     * 查询护士职业资格管理列表
     */
    @ApiOperation("查询护士职业资格管理列表")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:list')")
    @GetMapping("/list")
    public TableDataInfo list(Enclosure enclosure) {
        startPage();
        List<Enclosure> list = iEnclosureService.queryList(enclosure);
        return getDataTable(list);
    }

    /**
     * 导出护士职业资格管理列表
     */
    @ApiOperation("导出护士职业资格管理列表")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:export')" )
    @Log(title = "护士职业资格管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(Enclosure enclosure) {
        List<Enclosure> list = iEnclosureService.queryList(enclosure);
        ExcelUtil<Enclosure> util = new ExcelUtil<Enclosure>(Enclosure.class);
        return util.exportExcel(list, "enclosure" );
    }

    /**
     * 获取护士职业资格管理详细信息
     */
    @ApiOperation("获取护士职业资格管理详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(iEnclosureService.getById(id));
    }

    /**
     * 新增护士职业资格管理
     */
    @ApiOperation("新增护士职业资格管理")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:add')" )
    @Log(title = "护士职业资格管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Enclosure enclosure) {
        enclosure.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iEnclosureService.save(enclosure) ? 1 : 0);
    }

    /**
     * 修改护士职业资格管理
     */
    @ApiOperation("修改护士职业资格管理")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:edit')" )
    @Log(title = "护士职业资格管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Enclosure enclosure) {
        return toAjax(iEnclosureService.updateById(enclosure) ? 1 : 0);
    }

    /**
     * 删除护士职业资格管理
     */
    @ApiOperation("删除护士职业资格管理")
    @PreAuthorize("@ss.hasPermi('nursing:enclosure:remove')" )
    @Log(title = "护士职业资格管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(iEnclosureService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
